package org.sith.taskrunner.gwt.client.event;


import com.google.gwt.event.shared.GwtEvent;
import org.sith.taskrunner.gwt.shared.proxy.UserEntityProxy;

public class UserManageEvent extends GwtEvent<UserManageEventHandler> {

    public UserEntityProxy getUser() {
        return user;
    }

    public void setUser(UserEntityProxy user) {
        this.user = user;
    }

    public void setEventType(EventType eventType) {
        this.eventType = eventType;
    }

    public enum EventType {
        ADD_USER,
        REMOVE_USER,
        UPDATE_USER_ACTIVE_STATE,
        UPDATE_USER_ROLE,
        UPDATE_USER,
    }

    private EventType eventType;
    private UserEntityProxy user;


    public static final Type<UserManageEventHandler> TYPE = new Type<UserManageEventHandler>();

    @Override
    public Type<UserManageEventHandler> getAssociatedType() {
        return TYPE;
    }

    @Override
    protected void dispatch(UserManageEventHandler handler) {

        switch (eventType) {
            case ADD_USER: {
                handler.onUserAdded(this);
            }
            break;
            case REMOVE_USER: {
                handler.onUserRemoved(this);
            }
            break;
            case UPDATE_USER_ACTIVE_STATE: {
                handler.onUserActiveStateUpdated(this);
            }
            break;
            case UPDATE_USER_ROLE: {
                handler.onUserRoleUpdated(this);
            }
            break;
            case UPDATE_USER: {
                handler.onUserUpdated(this);
            }
            break;

            default: {

            }
        }

    }
}
